package com.andy.qhb.game;

import static com.andy.qhb.game.GameUtils.userCoinLog;

import java.util.Map;

import com.andy.qhb.vo.ShowMsg;
import com.google.common.collect.Maps;

public class RewardUtil {
	
	/**
	 * 扫雷系统奖励
	 * @param coin
	 * @param user
	 * @param qhbGame
	 */
	public static void rewardQb(int coin, GameUser user,QhbGame qhbGame) {
		// 1234-6789
		for(int i=0;i<6;i++) {
			if(coin == 1234+i*1111) {
				int dealCoin = GameConf.qbReward[i<4?0:1];
				userCoinLog(user, dealCoin, 6,qhbGame.getId());
				addRewMsg(coin, user, qhbGame, dealCoin);
				return;
			}
		}
		// 7654-4321
		for(int i=0;i<4;i++) {
			if(coin == 7654-i*1111) {
				int dealCoin = GameConf.qbReward[2];
				userCoinLog(user, dealCoin, 6,qhbGame.getId());
				addRewMsg(coin, user, qhbGame, dealCoin);
				return;
			}
		}
		// 1111-8888
		for(int i=0;i<8;i++) {
			if(coin == 1111+i*1111) {
				int dealCoin = GameConf.qbReward[i<5?3:4];
				userCoinLog(user, dealCoin, 6,qhbGame.getId());
				addRewMsg(coin, user, qhbGame, dealCoin);
				return;
			}
		}
		if(coin == 12345) {
			int dealCoin = GameConf.qbReward[5];
			userCoinLog(user, dealCoin, 6,qhbGame.getId());
			addRewMsg(coin, user, qhbGame, dealCoin);
			return;
		}
		if(coin == 34567) {
			int dealCoin = GameConf.qbReward[6];
			userCoinLog(user, dealCoin, 6,qhbGame.getId());
			addRewMsg(coin, user, qhbGame, dealCoin);
			return;
		}
		// 11111-44444
		for(int i=0;i<4;i++) {
			if(coin == 11111+i*11111) {
				int dealCoin = GameConf.qbReward[7+i];
				userCoinLog(user, dealCoin, 6,qhbGame.getId());
				addRewMsg(coin, user, qhbGame, dealCoin);
				return;
			}
		}
		if(coin == 1) {
			int dealCoin = GameConf.qbReward[11];
			userCoinLog(user, dealCoin, 6,qhbGame.getId());
			addRewMsg(coin, user, qhbGame, dealCoin);
			return;
		}
		// 123-789
		for(int i=0;i<7;i++) {
			if(coin == 123+i*111) {
				int dealCoin = GameConf.qbReward[12];
				userCoinLog(user, dealCoin, 6,qhbGame.getId());
				addRewMsg(coin, user, qhbGame, dealCoin);
				return;
			}
		}
		// 987-321
		for(int i=0;i<7;i++) {
			if(coin == 987-i*111) {
				int dealCoin = GameConf.qbReward[13];
				userCoinLog(user, dealCoin, 6,qhbGame.getId());
				addRewMsg(coin, user, qhbGame, dealCoin);
				return;
			}
		}
		// 111-999
		for(int i=0;i<9;i++) {
			if(coin == 111+i*111) {
				int dealCoin = GameConf.qbReward[14];
				userCoinLog(user, dealCoin, 6,qhbGame.getId());
				addRewMsg(coin, user, qhbGame, dealCoin);
				return;
			}
		}
		
		if(coin == 9999) {
			int dealCoin = GameConf.qbReward[15];
			userCoinLog(user, dealCoin, 6,qhbGame.getId());
			addRewMsg(coin, user, qhbGame, dealCoin);
			return;
		}
		
	}
	
	public static void addRewMsg(int coin, GameUser user,QhbGame qhbGame,int dealCoin) {
		// 抢包奖励提示
		ShowMsg showMsg = new ShowMsg(1,user.forOther());
		Map<String,Object> gameData = Maps.newHashMap();
		gameData.put("gcoin", qhbGame.getCoin());
		gameData.put("lei", qhbGame.getLei());
		gameData.put("coin", coin);
		gameData.put("rew", dealCoin);
		showMsg.setMsg(gameData );
		qhbGame.room().addMsg(showMsg);
	}

	/**
	 * 发包奖励
	 * @param zcount
	 * @param leiNum
	 * @param creater
	 * @param qhbGame
	 */
	public static void rewardFb(int zcount,int leiNum,GameUser creater, QhbGame qhbGame) {
		int num = qhbGame.getNum();
		if(num == 7) {
			if(leiNum == 1) {
				if(zcount > 2 && zcount < 7) {
					GameUtils.userCoinLog(creater, GameConf.fbReward71[zcount-3], num, qhbGame.getId());
				}
			}else if(leiNum == 2) {
				if(zcount > 3) {
					GameUtils.userCoinLog(creater, (zcount-3)*qhbGame.getCoin()/2, num, qhbGame.getId());
				}
			}else if(leiNum == 3) {
				if(zcount > 4) {
					GameUtils.userCoinLog(creater, (zcount-3)*qhbGame.getCoin()/2, num, qhbGame.getId());
				}
			}
		}else if(num == 8) {
			if(leiNum == 1) {
				if(zcount > 3) {
					GameUtils.userCoinLog(creater, (zcount-3)*qhbGame.getCoin()/2, num, qhbGame.getId());
				}
			}else if(leiNum == 2) {
				if(zcount > 4) {
					GameUtils.userCoinLog(creater, (zcount-4)*qhbGame.getCoin(), num, qhbGame.getId());
				}
			}else if(leiNum == 3) {
				if(zcount > 4) {
					GameUtils.userCoinLog(creater, (zcount-3)*qhbGame.getCoin()/2, num, qhbGame.getId());
				}
			}
		}
	}
	
}

